package crmsystem.controller;


import crmsystem.entity.BusinessEntity;
import crmsystem.service.BusinessService;
import crmsystem.utils.PageUtils;
import crmsystem.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * @author zhugaowei
 * @email 1912431877@qq.com
 * @date 2021-01-07 12:48:11
 */
@RestController
@RequestMapping("/business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    /**
     * 查出所有经办人
     */
    @RequestMapping("/infoByGestores")
    public R infoByGestores() {
        List<String> entities = businessService.getByGestores();
        return R.ok().put("gestores",entities);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("com:business:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = businessService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("com:business:info")
    public R info(@PathVariable("id") Integer id) {
        BusinessEntity business = businessService.getById(id);

        return R.ok().put("business", business);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("com:business:save")
    public R save(@Valid @RequestBody BusinessEntity business) {
        businessService.save(business);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("com:business:update")
    public R update(@Valid @RequestBody BusinessEntity business) {
        businessService.updateById(business);

        return R.ok();
    }

    /**
     * 批量删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("com:business:delete")
    public R delete(@RequestBody Integer[] ids) {
        businessService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 根据id删除
     */
    @RequestMapping("/delete/{id}")
    //@RequiresPermissions("com:business:delete")
    public R deleteById(@PathVariable("id") Integer id) {
        businessService.removeById(id);
        return R.ok();
    }

    /**
     * 多字段模糊查询
     */
    @RequestMapping("/infoByIndex/{index}")
    //@RequiresPermissions("com:contactperson:info")
    public R infoByIndex(@PathVariable("index") String index) {
        List<BusinessEntity> entities = businessService.getByIndex(index);
        return R.ok().put("entities", entities);
    }
}
